
package com.yuan.graduate;

import com.yuan.adapt.AdaptListUtils;
import com.yuan.adapt.CommAdapt;
import com.yuan.application.BaseActivity;
import com.yuan.dialog.CustomProgressDialog;
import com.yuan.unit.AsyncDataJobHandler;
import com.yuan.unit.ToastHelper;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Adapter;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;

import java.util.List;

/**
 * 查看请假界面
 * 
 * @author YUAN
 */
@SuppressLint("HandlerLeak")
public class SeeLeaveActivity extends BaseActivity implements OnItemClickListener {
    private Handler mHandler = null;
    private Context mContext = null;
    private ListView mListView = null;
    private TextView mTextView = null;
    private CustomProgressDialog mCustomProgressDialog = null;
    private List<?> list = null;

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_seeleave);
        mContext = this;
        mHandler = new Handler() {
            public void handleMessage(Message msg) {
                if (mCustomProgressDialog != null && mCustomProgressDialog.isShowing())
                {
                    mCustomProgressDialog.dismiss();
                    mCustomProgressDialog = null;
                }
                switch (msg.what) {
                    case GETALLLEAVEACCOUNTSUCCEED:
                        initListView();
                        break;
                    case GETALLLEAVEACCOUNTFILED:
                        ToastHelper.getInstance().shortToast(mContext, "获取失败");
                        break;
                    default:
                        break;
                }
            }
        };
        initView();

    }

    @Override
    protected void onResume() {
        super.onResume();
        AsyncDataJobHandler.getInstance().getAllLeaveAccount(mHandler);
    }

    private void initView() {
        // TODO Auto-generated method stub

        mListView = (ListView) findViewById(R.id.see_leave_list);
        mTextView = (TextView) findViewById(R.id.title);
        mTextView.setText("全部请假记录");
        mCustomProgressDialog = new CustomProgressDialog(mContext);
        mCustomProgressDialog.setUpdateMsg("正在初始化列表...");
        mCustomProgressDialog.show();

    }

    private void initListView() {
        // TODO Auto-generated method stub
        list = AdaptListUtils.getInstance().getAllLeaveAccountList();
        Adapter listAdapter = new CommAdapt(mContext, list, "申请日期");
        mListView.setAdapter((ListAdapter) listAdapter);
        mListView.invalidate();
        mListView.setOnItemClickListener(this);
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        // TODO Auto-generated method stub
        Intent mIntent = new Intent(mContext, LeaveInfoActivity.class);
        mIntent.putExtra("position", position);
        startActivity(mIntent);
    }
}
